/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package samoloty.controler;

import Utils.DoublePoint;
import java.awt.Point;
import java.util.ArrayList;
import samoloty.model.IDataModel;
import samoloty.model.models.LimitTowModel;
import samoloty.model.models.LimitZfwModel;
import samoloty.view.PlotPanel;

/**
 *
 * @author borysfan
 */
public class PlotPanelControler {
    private PlotPanel panel;
    private Controler controler;
    private IDataModel dataModel=null;

    public PlotPanelControler(Controler c){
        controler = c;
        initPanel();
    }

    public PlotPanelControler(Controler c,IDataModel data){
        controler = c;
        dataModel = data;
        initPanel();
    }

    public PlotPanel getPanel(){
        return panel;
    }

    public void setDataModel(IDataModel data){
        dataModel = data;
        initData();
    }

    private void initPanel() {
        panel = new PlotPanel();
        initData();
    }

    private void initData() {
        if(dataModel!=null){
            ArrayList<DoublePoint> pointsFwd = new ArrayList<DoublePoint>();
            ArrayList<DoublePoint> pointsAft = new ArrayList<DoublePoint>();

            ArrayList<LimitTowModel> data = dataModel.getLimitTow();
            for(int i=0;i<data.size();i++){
                double fx = data.get(i).getIndexFwd();
                int fy = data.get(i).getWeightFwd();
                pointsFwd.add(new DoublePoint(fx,fy));

                double ax = data.get(i).getIndexAft();
                int ay = data.get(i).getWeightAft();
                pointsAft.add(new DoublePoint(ax,ay));
            }
            panel.setFwdPoints(pointsFwd);
            panel.setAftPoints(pointsAft);
            

            ArrayList<DoublePoint> pointsZfwFwd = new ArrayList<DoublePoint>();
            ArrayList<DoublePoint> pointsZfwAft = new ArrayList<DoublePoint>();
            ArrayList<LimitZfwModel> dataZfw = dataModel.getLimitZfw();
            for(int i=0;i<dataZfw.size();i++){
                double fx = dataZfw.get(i).getIndexFwd();
                int fy = dataZfw.get(i).getWeightFwd();
                pointsZfwFwd.add(new DoublePoint(fx,fy));

                double ax = dataZfw.get(i).getIndexAft();
                int ay = dataZfw.get(i).getWeightAft();
                pointsZfwAft.add(new DoublePoint(ax,ay));
            }
            panel.setZfwFwdPoints(pointsZfwFwd);
            panel.setZfwAftPoints(pointsZfwAft);

        
            panel.update();
        }
    }





    public void update(){
        System.err.println("update");
        InfoPanelControler infoControler = controler.getInfoPanelControler();
        panel.set_vdow(infoControler.compute_vdow());
        panel.set_vazfw(infoControler.compute_azfw());
        panel.set_vdoi(infoControler.compute_vdoi());
        panel.set_vatow(infoControler.compute_vatow());
        panel.set_vtowi(infoControler.compute_vtowi());
        panel.set_vzfwi(infoControler.compute_vzfwi());
        panel.set_vlavi(infoControler.compute_vlawi());
        panel.set_valaw(infoControler.compute_valaw());
        panel.update();
        panel.repaint();;
}

    public void repaint(){
        
    }


}
